package edu.its.dreamteam.web.pages.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry.OptionGroupModel;
import org.apache.tapestry.OptionModel;
import org.apache.tapestry.SelectModel;
import org.apache.tapestry.SelectModelVisitor;
import org.apache.tapestry.internal.OptionModelImpl;
import org.apache.tapestry.internal.SelectModelImpl;

import edu.its.dreamteam.daf.beans.Formation;

public class FormationSelectionModel implements SelectModel {
	private List<Formation> formationList;
	
	public FormationSelectionModel(List<Formation> formationList){
		this.formationList = formationList;
	}
	public List<OptionGroupModel> getOptionGroups() {
		return getSelectModel().getOptionGroups();
	}

	public List<OptionModel> getOptions() {
		return getSelectModel().getOptions();
	}

	public void visit(SelectModelVisitor visitor) {
		getSelectModel().visit(visitor);

	}
	
	public SelectModel getSelectModel() {
		List<OptionModel> optionModelList = new ArrayList<OptionModel>();
		
		for(Formation formation: formationList) {			
			optionModelList.add(new OptionModelImpl(formation.getFormation(), false, formation, new String[0]));
		} 
		return new SelectModelImpl(null, optionModelList); 
	}

}
